package com.wise.controller;

import com.wise.test.WebSocketServer;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.concurrent.CopyOnWriteArraySet;

/**
 * @author rzc
 * @date 2021/12/10
 */
@RestController
public class TestController {
    @GetMapping("/test")
    public void testSend(){
        CopyOnWriteArraySet<WebSocketServer> webSocketSet = WebSocketServer.getWebSocketSet();
        for (WebSocketServer webSocketServer : webSocketSet) {
            //持续发送颜色文本到前台，前台根据颜色更新画笔颜色
            String[] colours=
                    {"red","lightpink","purple","yellow","black","while","blue","gray","red","lightpink","purple"};
            for (int i = 0; i < 10; i++) {
                try {
                    Thread.sleep(2000);
                    webSocketServer.sendMessage(colours[i]);
                } catch (InterruptedException | IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
